import {
    INIT_CART_LIST,
    DEL_ONE_SHOP,
    ONE_SHOP_DEAL,
    IS_CHECKED_ALL,
    ONE_SHOP_CHECKED
} from './mutations-type'

import ajax from './../api/index';

export default {

    // 1 初始化购物车数据
    reqShopList({commit}){
        ajax('http://demo.itlike.com/web/jdm/api/shoplist').then((res)=>{
            if(res.status == 200){
              const shopList = res.result.shopList;
              commit(INIT_CART_LIST,{shopList})
            } 
          }).catch((error)=>{
            console.log(error);
            alert('网络异常')
        })
    },

    // 2 删除一个商品
    delOneShop({commit},index){
        commit(DEL_ONE_SHOP,{index});
    },
 
    // 3 单个商品加减
    oneShopDeal({commit},{shop,flag}){
        commit(ONE_SHOP_DEAL,{shop,flag});
    },

    // 4 全选和取消全选
    CheckAllOrNot({commit},flag){
        commit(IS_CHECKED_ALL,{flag});
    },

    // 5 单个商品选择和取消
    oneShopChecked({commit},shop){
        commit(ONE_SHOP_CHECKED,{shop})
    }

}